/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import ProList from '@ant-design/pro-list';
import type { ActionType } from '@ant-design/pro-table';
import { Button, Space, Popconfirm } from 'antd';
import { useSmsExamine } from '../_utils';
import styles from './index.less';
import AuditContent from './content';
import AuditTitle from './title';

const KbSmsAudit = () => {
  const actionRef = useRef<ActionType>();
  const { getList, pagination, reload, handleUpdate, handleOperate, handleJump } = useSmsExamine({
    key: 'wait',
    actionRef,
  });

  return (
    <ProList
      className={styles.smsAudit}
      actionRef={actionRef}
      pagination={pagination}
      itemLayout='vertical'
      rowKey='id'
      request={getList}
      toolBarRender={() => {
        return [
          <Button key='reload' onClick={reload} type='primary'>
            刷新
          </Button>,
        ];
      }}
      metas={{
        title: {},
        subTitle: {
          dataIndex: 'cm_phone',
          render: (_, record) => <AuditTitle record={record} handleUpdate={handleUpdate} />,
        },
        content: {
          render: (_, record) => <AuditContent record={record} handleJump={handleJump} />,
        },
        actions: {
          render: (_, record) => {
            return (
              <Space key='actions' direction='horizontal'>
                <Popconfirm
                  title='系统将自动发送该批短信，是否继续？'
                  onConfirm={handleOperate.bind(null, 'pass', record)}
                >
                  <Button type='primary'>通过</Button>
                </Popconfirm>
                <Popconfirm
                  title='系统将不发送该批短信，是否继续？'
                  onConfirm={handleOperate.bind(null, 'reject', record)}
                >
                  <Button danger>拒绝</Button>
                </Popconfirm>
                <Popconfirm
                  title='系统将拒绝该用户待审核短信，并拉黑该用户，是否继续？'
                  onConfirm={handleOperate.bind(null, 'black', record)}
                >
                  <Button danger type='primary'>
                    拒绝并拉黑
                  </Button>
                </Popconfirm>
                <Popconfirm
                  title='是否将该用户设为扣钱不发? '
                  onConfirm={handleOperate.bind(null, 'shield', record)}
                >
                  <Button type='primary'>扣钱不发</Button>
                </Popconfirm>
              </Space>
            );
          },
        },
      }}
    />
  );
};

export default KbSmsAudit;
